package com.weilun.controller;

import com.weilun.pojo.Emp;
import com.weilun.pojo.LoginInfo;
import com.weilun.pojo.Result;
import com.weilun.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private EmpService empService;

    @PostMapping
    public Result login(@RequestBody Emp emp){
            log.info("员工登录, {}",emp);
            LoginInfo info = empService.login(emp);
            if (info != null){
                return Result.success(info);
            }
            return Result.error("用户名或密码错误");
    }
}
